package nobu.nakata.nfcfare.table;

import java.io.Serializable;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.users.User;

@PersistenceCapable(detachable="true")
public class TrainStationHistory implements Serializable, ILongCollectionKeyEntity {
	@PrimaryKey
	@Persistent
	private Key key;
	@Persistent
	private Long trainCode;
	@Persistent
	private String name;
	@Persistent
	private User editor;
	@Persistent
	private Long createdAt;
	
	
	public TrainStationHistory(Long trainCode, String name, User editor, Long createdAt) {
		this.key		= makeKey(trainCode, createdAt);
		this.trainCode	= trainCode;
		this.name		= name;
		this.editor		= editor;
		this.createdAt	= createdAt;
	}
	
	public Key getKey() { return key; }
	public Long getTrainCode() { return trainCode; }
	public String getName() { return name; }
	public User getUser() { return editor; }
	public Long getCreatedAt() { return createdAt; }
	
	// Interface for ILongCollectionKeyEntity
	public Long getCollectionKey() { return trainCode; }
	/**
	 * 
	 */
	public static final String KIND = TrainStationHistory.class.getSimpleName();

	private static final long serialVersionUID = -8630188442465092103L;

	public static Key makeKey(Long trainCode, Long createdAt) {
		return KeyFactory.createKey(KIND, String.format("%1$d:%2$d", trainCode, createdAt));
	}
}
